/*
 * @Author: 李超越 1509572300@qq.com
 * @Date: 2024-09-13 21:49:42
 * @LastEditors: 李超越 1509572300@qq.com
 * @LastEditTime: 2024-09-13 21:59:33
 * @FilePath: /my_git/lesson32_socket/InerAddr.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include "Log.hpp"

class InetAddr
{
private:
    void GetAddress(string *ip,uint16_t *port)
    {
        *port = ntohs(_addr.sin_port);
        *ip = inet_ntoa(_addr.sin_addr);
    }

public:
    InetAddr(const struct sockaddr_in &addr):_addr(addr)
    {
        GetAddress(&_ip, &_port);
    }

    string Ip()
    {
        return _ip;
    }

    uint16_t Port()
    {
        return _port;
    }

    ~InetAddr()
    {}

private:
    struct sockaddr_in _addr;
    string _ip;
    uint16_t _port;
};